import Vue from "vue";
// 引入 vue-router第三方的包
import VueRouter from "vue-router";

// 引入组件模块
import Find from "@/views/Find";
import My from "@/views/My";
import Part from "@/views/Part";
import NotFound from "@/views/NotFound";
import Recommend from "@/views/Second/Recommend.vue";
import Ranking from "@/views/Second/Ranking.vue";
import SongList from "@/views/Second/SongList.vue";

// 注册全局组件
Vue.use(VueRouter);

// 生成路由对象定义规则数组
const router = new VueRouter({
  // mode:'history',
  mode: "hash",
  routes: [
    {
      // 重定向
      path: "/", // 当地址为根路径是
      redirect: "/find", // 强制跳转到find组件页面
    },
    {
      path: "/find",
      name: "Find",
      component: Find,
      children: [
        {
          path: "recommend",
          name: "Recommend",
          component: Recommend,
        },
        {
          path: "ranking",
          name: "Ranking",
          component: Ranking,
        },
        {
          path: "songlist",
          name: "SongList",
          component: SongList,
        },
      ],
    },
    {
      path: "/my",
      name: "My",
      component: My,
    },
    {
      path: "/part",
      name: "Part",
      component: Part,
    },
    {
      path: "/part/:username", // 有:的路径代表要接收具体的值
      component: Part,
    },
    {
      // 404
      path: "*", // 如果访问一个不存在的路径是
      component: NotFound, // 跳转到404组件页面
    },
  ],
});

// 向外暴露
export default router;
